package com.frozendogtears.audiogame;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class Player extends Actor {
	public AtlasRegion texture = Assets.m_player;
	private float speed = 10.0f;
	private float movement;

	public Player() {
		this.touchable = true;
		this.width = texture.getRegionWidth();
		this.height = texture.getRegionHeight();
		this.y = 50;
		this.x = 10;
	}

	@Override
	public void act(float delta) {
		if (this.x <= this.getStage().left()) {
			movement = speed;
			Assets.m_jumpSound.play();
		} else if (this.x >= (this.getStage().right() - this.width)) {
			movement = -speed;
			Assets.m_powerUpSound.play();
		}

//		this.x += movement;
		// this.y += 0.5f;
	}

	// @Override
	public boolean keyDown(int keycode) {
		// TODO Auto-generated method stub
		System.out.println("test6");
		if (keycode == Keys.RIGHT) {
			this.x += 2;
			return true;
		}
		return false;

	}

	@Override
	public boolean keyUp(int keycode) {
		// TODO Auto-generated method stub
		System.out.println("test5");
		return true;
	}

	@Override
	public boolean touchMoved(float x, float y) {
		// TODO Auto-generated method stub
		System.out.println("test1");
		return true;
	}

	@Override
	public boolean touchDown(float x, float y, int pointer) {
		// TODO Auto-generated method stub
		System.out.println("test2");
		return true;
	}

	@Override
	public void touchUp(float x, float y, int pointer) {
		// TODO Auto-generated method stub
		System.out.println("test3");
	}

	@Override
	public void touchDragged(float x, float y, int pointer) {
		// TODO Auto-generated method stub
		System.out.println("test4");
		this.x = x;
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		batch.draw(texture, this.x, this.y);
	}

	public Actor hit (float x, float y) {
		return x > 0 && x < width && y > 0 && y < height ? this : null;
	}
}
